# SimpleLogger example

from peripherals import OutputController

class SimpleLogger(OutputController):
	
	def __init__(self):
		OutputController.__init__(self)	

	def GeomAdded(self, geom):
		print "Geom added"
	
	def GeomRemoved(self, geom):
		print "Geom removed"
		
	def GeomUpdated(self, geom):
		print geom.GetLabel() + " " + str(geom.GetID()) + " updated"

class AdvancedLogger(OutputController):
	def __init__(self):
		#call the OutputController constructor
		OutputController.__init__(self)
		self.__log = open("AdvancedLogger.log", 'w')
	
	def __del__(self):
		self.__log.flush()
		
		# close journal
		self.__log.close()	
					
	def GeomPositionUpdated(self, geom):
		#get the position of the geom
		x,y,z = geom.GetPosition()
		
		#get the id of the geom
		id = geom.GetID()
		
		#write position to log
		self.__log.write("Geom " + str(id) + " now at :" + str(x) + "," + str(y) + "," + str(z) + "\n")
		
	def InstrumentScaleXUpdated(self, instrument):
		#get the scale of the geom
		x,y,z = geom.GetScale()
		
		#get the id of the geom
		id = geom.GetPosition()
		
		#write to log
		self.__log.write("Geom " + str(id) + " x scalled to " + str(x) + "\n")
		